import { fileURLToPath, URL } from 'node:url'

import { defineConfig, loadEnv } from 'vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'

// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  envDir: process.cwd(),
  envPrefix: 'VITE_',
  define: {
    'process.env': {}
  },
  loadEnv(mode) {
    const env = loadEnv(mode, process.cwd())
    Object.entries(env).forEach(([key, val]) => {
      process.env[key] = val
    })
  },
  plugins: [
    vue(),
    Components({
      dts: false,
      resolvers: [VantResolver({ importStyle: false })]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    open: true,
    host: '0.0.0.0',
    cors: true,
    port: 3100
  },
  build: {
    outDir: 'dist',
    assetsDir: 'assets'
  },
})
